package main

import "fmt"

type TreeNode struct {
	val       int
	leftNode  *TreeNode
	rightNode *TreeNode
}

func main() {
	root := TreeNode{val: 8}
	root.leftNode = &TreeNode{val: 3}
	root.rightNode = &TreeNode{val: 10}
	root.leftNode.leftNode = &TreeNode{val: 1}
	root.leftNode.rightNode = &TreeNode{val: 6}
	root.leftNode.rightNode.leftNode = &TreeNode{val: 4}
	root.leftNode.rightNode.rightNode = &TreeNode{val: 7}
	root.rightNode.rightNode = &TreeNode{val: 14}
	root.rightNode.rightNode.leftNode = &TreeNode{val: 13}

	fmt.Println(inorderTraversal(&root))
}

var count int

func inorderTraversal(root *TreeNode) []int {
	// 第一步：判断输入条件是否合法
	// 第二步：判断递归是否应该结束
	if root == nil {
		return nil
	}

	var result []int
	result = append(result, inorderTraversal(root.leftNode)...)
	result = append(result, root.val)
	count++
	if count == 3 {
		fmt.Println(root.val)
	}
	result = append(result, inorderTraversal(root.rightNode)...)

	return result
}
